const BaseIpcHandler = require('../BaseIpcHandler');

// 从目录解析所有的视频
class ExtractFramesHandler extends BaseIpcHandler {
    async handle(event, params) {
        // 解析参数
        console.log('>> ExtractFramesHandler params = ', params);
        const { taskId, dir, fps, quality } = params;

        // 业务逻辑
        let result = null;
        try {
            this.app.video.extractFromDir(taskId, dir, fps, quality);
            result = { code: 0, msg: '开始抽取视频帧...' };
        } catch (error) {
            result = { code: -1, msg: error.message };
        }

        // 返回结果
        if (event.from === 'localserver') {
            event.resp.send(result);
        } else {
            return result;
        }
    }
}

module.exports = ExtractFramesHandler;
